package com.atcper

/**
 * @author : ranzlupup
 * @date : 2023/2/22 08:39
 */
object Scala05_function {
    def main(args: Array[String]): Unit = {
        val name: String = "ranzili"
        val name2: String = name.substring(0, 1).toUpperCase() + name.substring(1)
        println(name2)

        val x = 1
        val functionTest = (x: Int) => x + 1
        println(functionTest(x))

        def toBigFirst(string: String): String = {
            println(s"$string")
            string.substring(0, 1).toUpperCase() + string.substring(1)
        }

        println(toBigFirst(name))

        def name222: String = System.getProperty("user.name")
        println("Hello, " + name222 + "!")

        //        println(toBigFirst(name))
        //        test()
        //        test

        def test(): Unit = {
            println("This is a function...")
        }

        val t: () => Unit = test
        t()
        test()

        // 函数可以作为参数进行传递
        def f(f1: (Int, Int) => Int) = {
            f1(2, 4)
        }

        def add(a: Int, b: Int): Int = a + b

        // println(f(add))


        // 函数可以作为函数返回值返回
        def f2() = {
            def f3() = {
                println("f3............")
            }
            f3 _
        }

        //        val ff = f2()
        //        ff()
        //        f2()()


    }

    def test(): Unit = {
        println("This is a method...")
    }
}
